<%@ include file="../includes/topInclude.jsp" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<script type="text/javascript" src="js/userScript.js" ></script>
<!-- Support for Spring errors object -->
<spring:bind path="userForm.*">
    <c:forEach var="error" items="${status.errorMessages}">
        <B><FONT color=RED>
                <BR><c:out value="${error}"/>
        </FONT></B>
    </c:forEach>
</spring:bind>

<div id="content">
    <div class="post">
        <div class="title">
            <h2>User Form</h2>
            <p></p>
        </div>
        <div class="entry">       
            
            <c:if test="${userForm.newUser}">
                <form name="userFormHtml" action="<c:url value="userManagment.htm"/>" method="post">
            </c:if>
            <c:if test="${!userForm.newUser}">
                <form action="<c:url value="userManagment.htm"/>" method="post">
            </c:if>
            <table>
                <tr>
                    <td>Name</td>
                    <td>
                        <c:if test="${userForm.newUser}">
                            <spring:bind path="userForm.user.userId">
                                <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                            </spring:bind>
                        </c:if>
                        <c:if test="${!userForm.newUser}">
                            <c:out value="${userForm.user.userId}"/>
                        </c:if>
                    </td>
                </tr>    
                <tr>
                    <td>Password</td>
                    <td>
                        <spring:bind path="userForm.user.password">
                            <input type="password" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr>    
                <tr>
                    <td>Repeat Password</td>
                    <td>
                        <spring:bind path="userForm.repeatedPassword">
                            <input type="password" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr><tr>
                    <td>Role</td>
                    <td>
                        <spring:bind path="userForm.user.role">
                            <select name="<c:out value="${status.expression}"/>">
                                <c:forEach var="role" items="${roles}">
                                    <option 
                                        <c:if test="${role == status.value}">selected</c:if> value="<c:out value="${role}"/>">
                                        <c:out value="${role}"/>
                                    </option>
                                </c:forEach>
                            </select>
                        </spring:bind>
                    </td>
                </tr>    
                <tr>
                    <td>First Name:</td>
                    <td>
                        <spring:bind path="userForm.user.firstName">
                            <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr>    
                <tr>
                    <td>Last Name:</td>
                    <td>
                        <spring:bind path="userForm.user.lastName">
                            <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr>    
                <tr>
                    <td>Address:</td>
                    <td>
                        <spring:bind path="userForm.user.address">
                            <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr> 
                <tr>
                    <td>Phone:</td>
                    <td>
                        <spring:bind path="userForm.user.phone">
                            <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
                        </spring:bind>
                    </td>
                </tr> 
                <tr>
                    <td colspan="2" align="right"><input type="submit" value="Save" /></td>
                </tr>
            </table>
            <spring:bind path="userForm.user.id">
                <input type="hidden" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
            </spring:bind>        
            <input type="hidden" name="userAction" value="" />
            </form>       
        </div>
        <br/>
        <p class="links"> <a href="#" class="more">List of Users</a>  </p>
        
        <table>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Role</th>
            </tr>
            <c:forEach var="user" items="${usersList}" >
                <tr>
                    <td><a href="<c:url value="userManagment.htm"><c:param name="userAction" value="${user.id}"/></c:url>"><c:out value="${user.firstName}"/></a></td>
                    <td><c:out value="${user.lastName}"/></td>           
                    <td><c:out value="${user.role}"/></td>             
                    <td><small><a href="#" onClick="deleteUser('<c:out value="${user.id}"/>');"> Delete </a></small></td>    
                </tr>   
            </c:forEach>   
            
        </table>
    </div>
</div>
<%@ include file="../includes/bottomInclude.jsp" %>
